package com.cdyx.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.cdyx.model.cmn.Dict;
import com.cdyx.vo.cmn.DictEeVo;
import com.cdyx.yygh.cmn.EasyExcel.UserData;
import com.cdyx.yygh.cmn.mapper.DictMapper;
import org.springframework.beans.BeanUtils;

import java.util.Base64;
import java.util.Map;

public class Listener extends AnalysisEventListener<DictEeVo> {
    private DictMapper dictMapper;
    public Listener(DictMapper dictMapper) {
        this.dictMapper=dictMapper;
    }
    //从第三行开始一行一行读取数据
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dic=new Dict();
        BeanUtils.copyProperties(dictEeVo,dic);
        dic.setDictCode(new String(Base64.getDecoder().decode(dictEeVo.getDictCode())));
        dic.setValue(new String (Base64.getDecoder().decode(dictEeVo.getValue())));
        dic.setName(new String(Base64.getDecoder().decode(dictEeVo.getName())));
        dic.setId(Long.valueOf(new String(Base64.getDecoder().decode(dictEeVo.getNewId()))));
        dic.setParentId(Long.valueOf(new String(Base64.getDecoder().decode(dictEeVo.getNewParentId()))));
        dictMapper.insert(dic);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        super.invokeHeadMap(headMap, context);
    }
}
